#!/bin/bash
#
# Startup script for the PHP FastCGI server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php
# config: /etc/php.ini
 
# Source function library.
. /etc/rc.d/init.d/functions

NAME="sqlproxy" 
SQLPROXY="/home/vyouzhi/workspace/sqlproxy/devel_0.4/main"
SQLUSER=nobody
PIDFILE=/var/run/sqlproxy.pid

if [ -z "$SQL_CONF_PATH" ]; then
  SQL_CONF_PATH="/home/vyouzhi/workspace/sqlproxy/devel_0.4/sqlproxy.cnf"
fi


 
case "$1" in
  start)
        SQLPROXY_START=$"Starting ${NAME} service: "
        echo -n $SQLPROXY_START
 
        # check for $PHPUSER, create if non-existent
        if [ -z "`id -u $SQLUSER 2> /dev/null`" ]; then
            useradd -s /sbin/nologin $SQLUSER
        fi
 
        # clean environment
        E=
        #daemon --user $PHPUSER --pidfile $PIDFILE "env - $E $PHPFCGI -q -b $FCGIADDR:$FCGIPORT &> /dev/null &"
	ulimit -s 1024
 	$SQLPROXY -c $SQL_CONF_PATH -d
        pid=`pidof main`
        if [ -n "$pid" ]; then
            echo $pid > $PIDFILE
            success $PHPFCGI_START
        else
            failure $PHPFCGI_START
        fi
        echo
        ;;
  stop)
        echo -n "Stopping sqlproxy: "
        killproc -p $PIDFILE sqlproxy
        echo
        ;;
  status)
        status sqlproxy
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac
 
exit 0

